package com.qianli.cashmama.product.server.domain;

import com.alibaba.fastjson.JSON;
import com.fqgj.common.utils.StringUtils;
import com.qianli.cashmama.product.facade.enums.InterestStrategyEnum;
import com.qianli.cashmama.product.facade.enums.PaybackPeriodUnitEnum;
import com.qianli.cashmama.product.facade.enums.SellStatusEnum;
import com.qianli.cashmama.product.facade.result.CategoryConfig;
import com.qianli.cashmama.product.facade.result.ProductCategory;
import com.qianli.cashmama.product.facade.result.ProductRuleDetail;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by xuyang on 2017/7/18.
 */
public class ProductCategoryDomain {

    //类目代码
    private String code;

    //类目名称
    private String name;

    //类目金额下限, 用于创建类目时进行检查
    private BigDecimal moneyFloor;

    //类目金额上限, 用于创建类目时进行检查
    private BigDecimal moneyUpper;

    //每档金额，用于创建类目时进行检查
    private BigDecimal moneyStep;

    //是否上架
    /**
     * @see SellStatusEnum status
     */
    private SellStatusEnum isSelling;

    //计息方式
    private InterestStrategyEnum interestStrategy;

    //还款周期单位
    private PaybackPeriodUnitEnum paybackPeriodUnitEnum;

    //还款周期下限，用于创建类目时进行检查
    private Integer paybackPeriodFloor;

    //还款周期上限，用于创建类目时进行检查
    private Integer paybackPeriodUpper;

    //每档还款周期，用于创建类目时进行检查
    private Integer paybackPeriodStep;

    private String merchantCode;

    //类目的产品规则
    private List<BusinessRuleDetailDomain> productRules;
    /**
     * 产品类目配置 json格式
     */
    private String otherConfigData;

    /**
     * 类目logo
     */
    private String logo;
    /**
     * 类目描述
     */
    private String categoryDesc;
    /**
     * 类目类型
     */
    private Integer categoryType;
    /**
     * 申请比例
     */
    private Integer applyRate;
    /**
     *每日申请上限
     */
    private Integer dailyApplyLimit;
    /**
     *生效开始时间
     */
    private Date effectiveStartTime;
    /**
     *生效结束时间
     */
    private Date effectiveEndTime;
    /**
     *商户域名
     */
    private String merchantDoaminUrl;
    /**
     *商户公钥
     */
    private String merchantPublicKey;

    private Integer sort;

    /**
     * 确认提现步骤
     */
    private Integer confirmWithdrawProcess;

    private String extraInfo;

    private Integer forGp;

    public Integer getForGp() {
        return forGp;
    }

    public ProductCategoryDomain setForGp(Integer forGp) {
        this.forGp = forGp;
        return this;
    }

    public String getExtraInfo() {
        return extraInfo;
    }

    public ProductCategoryDomain setExtraInfo(String extraInfo) {
        this.extraInfo = extraInfo;
        return this;
    }

    public ProductCategory newFacade(boolean needRules) {
        ProductCategory productCategory = new ProductCategory();

        productCategory.setCode(code);
        productCategory.setName(name);
        productCategory.setMoneyFloor(moneyFloor.toString());
        productCategory.setMoneyUpper(moneyUpper.toString());
        productCategory.setMoneyStep(moneyStep.toString());
        productCategory.setIsSelling(isSelling.getStatus());
        productCategory.setInterestStrategy(interestStrategy.getCode());
        productCategory.setPaybackPeriodUnit(paybackPeriodUnitEnum.getCode());
        productCategory.setPaybackPeriodFloor(paybackPeriodFloor);
        productCategory.setPaybackPeriodUpper(paybackPeriodUpper);
        productCategory.setPaybackPeriodStep(paybackPeriodStep);
        productCategory.setMerchantCode(merchantCode);
        productCategory.setLogo(logo);
        productCategory.setApplyRate(applyRate);
        productCategory.setCategoryType(categoryType);
        productCategory.setCategoryDesc(categoryDesc);
        productCategory.setDailyApplyLimit(dailyApplyLimit);
        productCategory.setEffectiveStartTime(effectiveStartTime);
        productCategory.setEffectiveEndTime(effectiveEndTime);
        productCategory.setMerchantDoaminUrl(merchantDoaminUrl);
        productCategory.setMerchantPublicKey(merchantPublicKey);
        productCategory.setSort(sort);

        if (needRules && productRules != null) {
            List<ProductRuleDetail> facadeRules = new ArrayList<>();
            for (BusinessRuleDetailDomain ruleDetailDomain : productRules) {
                facadeRules.add(ruleDetailDomain.newFacade());
            }
            productCategory.setProductRules(facadeRules);
        }
        if (StringUtils.isNotEmpty(otherConfigData)) {
            productCategory.setCategoryConfig(JSON.parseObject(otherConfigData, CategoryConfig.class));
        } else {
            productCategory.setCategoryConfig(new CategoryConfig());
        }
        return productCategory;
    }


    public Integer getConfirmWithdrawProcess() {
        return confirmWithdrawProcess;
    }

    public ProductCategoryDomain setConfirmWithdrawProcess(Integer confirmWithdrawProcess) {
        this.confirmWithdrawProcess = confirmWithdrawProcess;
        return this;
    }

    public String getCode() {
        return code;
    }

    public ProductCategoryDomain setCode(String code) {
        this.code = code;
        return this;
    }

    public String getName() {
        return name;
    }

    public ProductCategoryDomain setName(String name) {
        this.name = name;
        return this;
    }

    public BigDecimal getMoneyFloor() {
        return moneyFloor;
    }

    public ProductCategoryDomain setMoneyFloor(BigDecimal moneyFloor) {
        this.moneyFloor = moneyFloor;
        return this;
    }

    public BigDecimal getMoneyUpper() {
        return moneyUpper;
    }

    public ProductCategoryDomain setMoneyUpper(BigDecimal moneyUpper) {
        this.moneyUpper = moneyUpper;
        return this;
    }

    public BigDecimal getMoneyStep() {
        return moneyStep;
    }

    public ProductCategoryDomain setMoneyStep(BigDecimal moneyStep) {
        this.moneyStep = moneyStep;
        return this;
    }

    public SellStatusEnum getIsSelling() {
        return isSelling;
    }

    public ProductCategoryDomain setIsSelling(SellStatusEnum isSelling) {
        this.isSelling = isSelling;
        return this;
    }

    public InterestStrategyEnum getInterestStrategy() {
        return interestStrategy;
    }

    public ProductCategoryDomain setInterestStrategy(InterestStrategyEnum interestStrategy) {
        this.interestStrategy = interestStrategy;
        return this;
    }

    public PaybackPeriodUnitEnum getPaybackPeriodUnitEnum() {
        return paybackPeriodUnitEnum;
    }

    public ProductCategoryDomain setPaybackPeriodUnitEnum(PaybackPeriodUnitEnum paybackPeriodUnitEnum) {
        this.paybackPeriodUnitEnum = paybackPeriodUnitEnum;
        return this;
    }

    public Integer getPaybackPeriodFloor() {
        return paybackPeriodFloor;
    }

    public ProductCategoryDomain setPaybackPeriodFloor(Integer paybackPeriodFloor) {
        this.paybackPeriodFloor = paybackPeriodFloor;
        return this;
    }

    public Integer getPaybackPeriodUpper() {
        return paybackPeriodUpper;
    }

    public ProductCategoryDomain setPaybackPeriodUpper(Integer paybackPeriodUpper) {
        this.paybackPeriodUpper = paybackPeriodUpper;
        return this;
    }

    public Integer getPaybackPeriodStep() {
        return paybackPeriodStep;
    }

    public ProductCategoryDomain setPaybackPeriodStep(Integer paybackPeriodStep) {
        this.paybackPeriodStep = paybackPeriodStep;
        return this;
    }

    public String getMerchantCode() {
        return merchantCode;
    }

    public ProductCategoryDomain setMerchantCode(String merchantCode) {
        this.merchantCode = merchantCode;
        return this;
    }

    public List<BusinessRuleDetailDomain> getProductRules() {
        return productRules;
    }

    public ProductCategoryDomain setProductRules(List<BusinessRuleDetailDomain> productRules) {
        this.productRules = productRules;
        return this;
    }

    public String getOtherConfigData() {
        return otherConfigData;
    }

    public ProductCategoryDomain setOtherConfigData(String otherConfigData) {
        this.otherConfigData = otherConfigData;
        return this;
    }

    public String getLogo() {
        return logo;
    }

    public ProductCategoryDomain setLogo(String logo) {
        this.logo = logo;
        return this;
    }

    public String getCategoryDesc() {
        return categoryDesc;
    }

    public ProductCategoryDomain setCategoryDesc(String categoryDesc) {
        this.categoryDesc = categoryDesc;
        return this;
    }

    public Integer getCategoryType() {
        return categoryType;
    }

    public ProductCategoryDomain setCategoryType(Integer categoryType) {
        this.categoryType = categoryType;
        return this;
    }

    public Integer getApplyRate() {
        return applyRate;
    }

    public ProductCategoryDomain setApplyRate(Integer applyRate) {
        this.applyRate = applyRate;
        return this;
    }

    public Integer getDailyApplyLimit() {
        return dailyApplyLimit;
    }

    public ProductCategoryDomain setDailyApplyLimit(Integer dailyApplyLimit) {
        this.dailyApplyLimit = dailyApplyLimit;
        return this;
    }

    public Date getEffectiveStartTime() {
        return effectiveStartTime;
    }

    public ProductCategoryDomain setEffectiveStartTime(Date effectiveStartTime) {
        this.effectiveStartTime = effectiveStartTime;
        return this;
    }

    public Date getEffectiveEndTime() {
        return effectiveEndTime;
    }

    public ProductCategoryDomain setEffectiveEndTime(Date effectiveEndTime) {
        this.effectiveEndTime = effectiveEndTime;
        return this;
    }

    public String getMerchantDoaminUrl() {
        return merchantDoaminUrl;
    }

    public ProductCategoryDomain setMerchantDoaminUrl(String merchantDoaminUrl) {
        this.merchantDoaminUrl = merchantDoaminUrl;
        return this;
    }

    public String getMerchantPublicKey() {
        return merchantPublicKey;
    }

    public ProductCategoryDomain setMerchantPublicKey(String merchantPublicKey) {
        this.merchantPublicKey = merchantPublicKey;
        return this;
    }

    public Integer getSort() {
        return sort;
    }

    public ProductCategoryDomain setSort(Integer sort) {
        this.sort = sort;
        return this;
    }
}
